<!-- src/components/Layout.vue -->
 <!-- 第六步：更新侧边栏菜单 -->
<template>
  <div class="layout-container">
    <!-- 顶部导航栏 -->
    <header class="header">
      <div class="header-content">
        <div class="header-left">
          <h1 class="logo">教务管理系统</h1>
        </div>
        <div class="header-right">
          <span class="welcome-text">欢迎，{{ userInfo?.username || '111' }}</span>
          <button @click="handleLogout" class="logout-btn">退出登录</button>
        </div>
      </div>
    </header>

    <div class="main-container">
      <!-- 侧边栏 -->
      <aside class="sidebar">
        <nav class="sidebar-nav">
          <router-link 
            to="/dashboard" 
            class="nav-item"
            :class="{ active: $route.path === '/dashboard' }"
          >
            📊 仪表盘
          </router-link>
          <router-link 
            to="/users" 
            class="nav-item"
            :class="{ active: $route.path === '/users' }"
          >
            👥 用户管理
          </router-link>
          <router-link 
            to="/courses" 
            class="nav-item"
            :class="{ active: $route.path === '/courses' }"
          >
            📚 课程管理
          </router-link>

<!-- src/components/Layout.vue -->
<!-- 在sidebar-nav中添加学生选课菜单项 -->
          <router-link 
            to="/course-selection" 
            class="nav-item"
            :class="{ active: $route.path === '/course-selection' }"
          >
            📚 学生选课
          </router-link>
          <router-link 
            to="/notices" 
            class="nav-item"
            :class="{ active: $route.path === '/notices' }"
          >
            📢 通知公告
          </router-link>
          <!-- 可以添加更多菜单项 -->
        </nav>
      </aside>

      <!-- 主内容区 -->
      <main class="main-content">
        <div class="content-wrapper">
          <!-- 路由出口 -->
          <router-view></router-view>
        </div>
      </main>
    </div>
  </div>
</template>

<script>
import { useRouter } from 'vue-router';
import { useUserStore } from '@/stores/user';

export default {
  name: 'Layout',
  setup() {
    const router = useRouter();
    const userStore = useUserStore();

    const handleLogout = () => {
      userStore.clearUser();
      router.push('/login');
    };

    return {
      userInfo: userStore.userInfo,
      handleLogout
    };
  }
};
</script>

<style scoped>
/* 重置所有元素的盒模型 */
* {
  box-sizing: border-box;
}

.layout-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: #f5f7fa;
}

.header {
  background-color: #2c3e50;
  color: white;
  height: 60px;
  flex-shrink: 0; /* 防止头部被压缩 */
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  position: relative;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  padding: 0 20px;
}

.logo {
  font-size: 20px;
  font-weight: bold;
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

.welcome-text {
  font-size: 14px;
}

.logout-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.logout-btn:hover {
  background: rgba(255,255,255,0.3);
}

/* 主容器使用flex布局 */
.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* 侧边栏固定在左侧 */
.sidebar {
  width: 250px;
  background-color: #34495e;
  color: white;
  overflow-y: auto;
  flex-shrink: 0; /* 防止侧边栏被压缩 */
  position: relative;
  z-index: 90;
}

.sidebar-nav {
  padding: 20px 0;
}

.nav-item {
  display: block;
  padding: 12px 20px;
  color: #ecf0f1;
  text-decoration: none;
  transition: background-color 0.3s;
  border-left: 4px solid transparent;
}

.nav-item:hover {
  background-color: #3c546b;
}

.nav-item.active {
  background-color: #3498db;
  border-left-color: #2980b9;
}

/* 主内容区占据剩余空间 */
.main-content {
  flex: 1;
  overflow-y: auto;
  background-color: #f5f7fa;
  padding: 20px;
  position: relative;
}

.content-wrapper {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  min-height: 100%;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .sidebar {
    width: 200px;
  }
  
  .main-content {
    padding: 10px;
  }
  
  .content-wrapper {
    padding: 15px;
  }
}
</style>